﻿//-------------------------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd.
//-------------------------------------------------------------------------------------

using System;
using System.Data;

namespace DotNet.BaseManager
{
    using DotNet.DbUtilities;
    using DotNet.Utilities;

    /// <summary>
    ///	DbLogic
    /// 通用基类
    ///
    /// 这个类可是修改了很多次啊，已经比较经典了，随着专业的提升，人也会不断提高，技术也会越来越精湛。
    ///
    /// 修改纪录
    ///
    ///
    ///		2010.07.08 版本：4.8	JiRiGaLa 增加 Insert 方法。
    ///		2009.01.15 版本：4.7	JiRiGaLa 将方法修改为 static 静态的，提高运行速度。
    ///		2009.01.05 版本：4.6	JiRiGaLa MySql 获取前几个的错误进行修正。
    ///		2008.06.03 版本：4.5	JiRiGaLa IN SQL语句调试、修改错误。
    ///		2008.05.31 版本：4.4	JiRiGaLa 改进 参数名param去掉了，变量名首字母小写了。
    ///		2008.05.09 版本：4.3	JiRiGaLa 改进 树型结构的数据的获得函数部分。
    ///		2007.11.08 版本：4.2	JiRiGaLa 改进 DataTableToStringList 为 FieldToList。
    ///		2007.11.05 版本：4.1	JiRiGaLa 改进 GetDS、GetDT 功能，整体思路又上一个台阶，基类的又一次飞跃。
    ///		2007.11.05 版本：4.0	JiRiGaLa 改进 支持不是“ID”为字段的主键表。
    ///		2007.11.01 版本：3.9	JiRiGaLa 改进 BUOperatorInfo 去掉这个变量，可以提高性能，提高速度，基类的又一次飞跃。
    ///		2007.09.13 版本：3.8	JiRiGaLa 改进 BUBaseBusinessLogic.SQLLogicConditional 错误。
    ///		2007.08.14 版本：3.7	JiRiGaLa 改进 WebService 模式下 DataSet 传输数据的速度问题。
    ///		2007.07.20 版本：3.6	JiRiGaLa 改进 DataSet 修改为 DataTable 应该能提高一些速度吧。
    ///		2007.05.20 版本：3.5	JiRiGaLa 改进 GetList() 方法整理，这次又应该是一次升华，质的飞跃很不容易啊，身心都有提高了。
    ///		2007.05.20 版本：3.4	JiRiGaLa 改进 Exists() 方法整理。
    ///		2007.05.13 版本：3.3	JiRiGaLa 改进 GetProperty()，SetProperty()，Delete() 方法整理。
    ///		2007.05.10 版本：3.2	JiRiGaLa 改进 GetList() 方法整理。
    ///		2007.04.10 版本：3.1	JiRiGaLa 添加 GetNextID，GetPreviousID 方法整理。
    ///		2007.03.03 版本：3.0	JiRiGaLa 进行了一次彻底的优化工作，方法的位置及功能整理。
    ///		2007.03.01 版本：2.0	JiRiGaLa 重新调整主键的规范化。
    ///		2006.02.05 版本：1.1	JiRiGaLa 重新调整主键的规范化。
    ///		2005.12.30 版本：1.0	JiRiGaLa 数据库连接方式都进行改进
    ///		2005.09.04 版本：1.0	JiRiGaLa 执行数据库脚本
    ///		2005.08.19 版本：1.0	JiRiGaLa 整理一下编排
    ///		2005.07.10 版本：1.0	JiRiGaLa 修改了程序，格式以及理念都有些提高，应该是一次大突破
    ///		2004.11.12 版本：1.0	JiRiGaLa 添加了最新的GetParent、GetChildren、GetParentChildren 方法
    ///		2004.07.21 版本：1.0	JiRiGaLa UpdateRecord、Delete、SetProperty、GetProperty、ExecuteNonQuery、GetRecord 方法进行改进。
    ///								还删除一些重复的主键，提取了最优化的方法，有时候写的主键真的是垃圾，可能自己也没有注意时就写出了垃圾。
    ///								GetRepeat、GetDayOfWeek、ExecuteProcedure、GetFromProcedure 方法进行改进，基本上把所有的方法都重新写了一遍。
    ///
    /// 版本：4.7
    ///
    /// <author>
    ///		<name>JiRiGaLa</name>
    ///		<date>2009.01.15</date>
    /// </author>
    /// </summary>
    public class DbLogic
    {
        #region public static string SqlSafe(string value) 检查参数的安全性

        /// <summary>
        /// 检查参数的安全性
        /// </summary>
        /// <param name="value">参数</param>
        /// <returns>安全的参数</returns>
        public static string SqlSafe(string value)
        {
            value = value.Replace("'", "''");

            // value = value.Replace("%", "'%");
            return value;
        }

        #endregion public static string SqlSafe(string value) 检查参数的安全性

        #region public static string GetWhereString(IDbHelper dbHelper, string[] names, ref Object[] values, string relation) 获得条件语句

        /// <summary>
        /// 获得条件语句
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="relation">逻辑关系</param>
        /// <returns>字符串</returns>
        public static string GetWhereString(IDbHelper dbHelper, string[] names, ref Object[] values, string relation)
        {
            string returnValue = string.Empty;
            string subSqlQuery = string.Empty;
            for (int i = 0; i < names.Length; i++)
            {
                if ((names[i] != null) && (names[i].Length > 0))
                {
                    //if (values[i] == null || String.IsNullOrEmpty(values[i].ToString()))
                    if (values[i] == null)
                    {
                        subSqlQuery = " (" + names[i] + " IS NULL) ";
                    }
                    else
                    {
                        if (values[i] is Array)
                        {
                            subSqlQuery = " (" + names[i] + " IN (" + BaseBusinessLogic.ArrayToList((string[])values[i], "'") + ")) ";
                        }
                        else
                        {
                            subSqlQuery = " (" + names[i] + " = " + dbHelper.GetParameter(names[i]) + ") ";

                            //if ((values[i].ToString().IndexOf('[') >= 0) || (values[i].ToString().IndexOf(']') >= 0))
                            //{
                            //    values[i] = values[i].ToString().Replace("[", "/[");
                            //    values[i] = values[i].ToString().Replace("]", "/]");
                            //    values[i] = SqlSafe(values[i].ToString());
                            //    subSqlQuery = " (" + names[i] + " LIKE '" + values[i] + "' ESCAPE '/') ";
                            //    values[i] = null;
                            //    subSqlQuery = " (" + names[i] + " LIKE ? ESCAPE '/') ";
                            //}
                        }

                        // 这里操作，就会有些重复了，不应该进行处理
                        // values[i] = this.SqlSafe(values[i].ToString());
                    }
                    returnValue += subSqlQuery + relation;
                }
            }
            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - relation.Length - 1);
            }
            return returnValue;
        }

        #endregion public static string GetWhereString(IDbHelper dbHelper, string[] names, ref Object[] values, string relation) 获得条件语句

        //
        // 对数据库进行操作的方法
        //

        #region public static string ExecuteScalar(IDbHelper dbHelper, string sqlQuery) 执行SQL查询

        /// <summary>
        /// 执行SQL查询
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name=sqlQuery>查询语句</param>
        /// <returns>字符串</returns>
        public static string ExecuteScalar(IDbHelper dbHelper, string sqlQuery)
        {
            string returnValue = string.Empty;
            object returnObject = dbHelper.ExecuteScalar(sqlQuery);
            if (returnObject != null)
            {
                returnValue = returnObject.ToString();
            }
            return returnValue;
        }

        #endregion public static string ExecuteScalar(IDbHelper dbHelper, string sqlQuery) 执行SQL查询

        #region public static int ExecuteNonQuery(IDbHelper dbHelper, string sqlQuery) 执行SQL查询

        /// <summary>
        /// 执行SQL查询
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="sqlQuery">sql查询</param>
        /// <returns>影响行数</returns>
        public static int ExecuteNonQuery(IDbHelper dbHelper, string sqlQuery)
        {
            return dbHelper.ExecuteNonQuery(sqlQuery);
        }

        #endregion public static int ExecuteNonQuery(IDbHelper dbHelper, string sqlQuery) 执行SQL查询

        #region public static int ExecuteNonQuery(IDbHelper dbHelper, string[] sqlQuerys) 执行SQL数组查询

        /// <summary>
        /// 执行SQL数组查询
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="sqlQuerys">查询语句数组</param>
        /// <returns>影响行数</returns>
        public static int ExecuteNonQuery(IDbHelper dbHelper, string[] sqlQuerys)
        {
            int returnValue = 0;
            string sqlQuery = string.Empty;
            for (int i = 0; i < sqlQuerys.Length; i++)
            {
                sqlQuery = sqlQuerys[i];

                // 执行SQL查询
                returnValue += ExecuteNonQuery(dbHelper, sqlQuery);
            }
            return returnValue;
        }

        #endregion public static int ExecuteNonQuery(IDbHelper dbHelper, string[] sqlQuerys) 执行SQL数组查询

        //
        // 判断数据是否已被更改
        //

        #region public static bool IsModifed(IDbHelper dbHelper, string tableName, Object id, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        /// <summary>
        /// 数据是否已经被别人修改了
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">表名</param>
        /// <param name="id">主键</param>
        /// <param name="oldModifiedUserId">最后修改者</param>
        /// <param name="oldModifiedOn">最后修改时间</param>
        /// <returns>已被修改</returns>
        public static bool IsModifed(IDbHelper dbHelper, string tableName, Object id, string oldModifiedUserId, DateTime? oldModifiedOn)
        {
            return IsModifed(dbHelper, tableName, BaseBusinessLogic.FieldId, id, oldModifiedUserId, oldModifiedOn);
        }

        #endregion public static bool IsModifed(IDbHelper dbHelper, string tableName, Object id, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        #region public static bool IsModifed(IDbHelper dbHelper, string tableName, string fieldName, Object fieldValue, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        /// <summary>
        /// 数据是否已经被别人修改了
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">表名</param>
        /// <param name="id">主键</param>
        /// <param name="fieldName">字段</param>
        /// <param name="fieldValue">值</param>
        /// <param name="oldModifiedUserId">最后修改者</param>
        /// <param name="oldModifiedOn">最后修改时间</param>
        /// <returns>已被修改</returns>
        public static bool IsModifed(IDbHelper dbHelper, string tableName, string fieldName, Object fieldValue, string oldModifiedUserId, DateTime? oldModifiedOn)
        {
            bool returnValue = false;
            string sqlQuery = " SELECT " + BaseBusinessLogic.FieldId
                            + "," + BaseBusinessLogic.FieldCreateUserId
                            + "," + BaseBusinessLogic.FieldCreateOn
                            + "," + BaseBusinessLogic.FieldModifiedUserId
                            + "," + BaseBusinessLogic.FieldModifiedOn
                            + " FROM " + tableName
                            + " WHERE " + fieldName + " = " + dbHelper.GetParameter(fieldName);
            DataTable dataTable = dbHelper.Fill(sqlQuery, dbHelper.MakeParameters(fieldName, fieldValue));
            returnValue = IsModifed(dataTable, oldModifiedUserId, oldModifiedOn);
            return returnValue;
        }

        #endregion public static bool IsModifed(IDbHelper dbHelper, string tableName, string fieldName, Object fieldValue, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        #region private static bool IsModifed(DataTable dataTable, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        /// <summary>
        /// 数据是否已经被别人修改了
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <param name="oldModifiedUserId">最后修改者</param>
        /// <param name="oldModifiedOn">最后修改时间</param>
        /// <returns>已被修改</returns>
        private static bool IsModifed(DataTable dataTable, string oldModifiedUserId, DateTime? oldModifiedOn)
        {
            bool returnValue = false;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                returnValue = IsModifed(dataRow, oldModifiedUserId, oldModifiedOn);
            }
            return returnValue;
        }

        #endregion private static bool IsModifed(DataTable dataTable, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        #region public static bool IsModifed(DataRow dataRow, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        /// <summary>
        /// 数据是否已经被别人修改了
        /// </summary>
        /// <param name="dataRow">数据行</param>
        /// <param name="oldModifiedUserId">最后修改者</param>
        /// <param name="oldModifiedOn">最后修改时间</param>
        /// <returns>已被修改</returns>
        public static bool IsModifed(DataRow dataRow, string oldModifiedUserId, DateTime? oldModifiedOn)
        {
            bool returnValue = false;
            if ((dataRow[BaseBusinessLogic.FieldModifiedUserId] == DBNull.Value) || ((dataRow[BaseBusinessLogic.FieldModifiedOn] == DBNull.Value)))
            {
                returnValue = false;
                return returnValue;
            }
            if (!dataRow[BaseBusinessLogic.FieldModifiedUserId].ToString().Equals(oldModifiedUserId))
            {
                returnValue = true;
                return returnValue;
            }

            DateTime newModifiedOn = DateTime.Parse(dataRow[BaseBusinessLogic.FieldModifiedOn].ToString());
            returnValue = oldModifiedOn != newModifiedOn;
            return returnValue;
        }

        #endregion public static bool IsModifed(DataRow dataRow, string oldModifiedUserId, DateTime? oldModifiedOn) 数据是否已经被别人修改了

        //
        // 读取属性部分
        //

        #region public static string GetProperty(IDbHelper dbHelper, string tableName, string name, string value, string targetField) 读取属性

        /// <summary>
        /// 读取属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">键值</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>属性</returns>
        public static string GetProperty(IDbHelper dbHelper, string tableName, string name, object value, string targetField)
        {
            string returnValue = string.Empty;
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            returnValue = GetProperty(dbHelper, tableName, names, values, targetField);
            return returnValue;
        }

        #endregion public static string GetProperty(IDbHelper dbHelper, string tableName, string name, string value, string targetField) 读取属性

        #region public static string GetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField) 读取属性

        /// <summary>
        /// 读取属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>String</returns>
        public static string GetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField)
        {
            string returnValue = string.Empty;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            names[1] = name2;
            values[0] = value1;
            values[1] = value2;
            returnValue = GetProperty(dbHelper, tableName, names, values, targetField);
            return returnValue;
        }

        #endregion public static string GetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField) 读取属性

        #region public static string GetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField) 读取属性

        /// <summary>
        /// 读取属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>属性</returns>
        public static string GetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField)
        {
            string returnValue = string.Empty;
            string sqlQuery = " SELECT " + targetField
                + " FROM " + tableName
                + " WHERE " + GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = returnObject.ToString();
            }
            return returnValue;
        }

        #endregion public static string GetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField) 读取属性

        #region public static string GetId(IDbHelper dbHelper, string tableName, string name, object value) 获得ID属性

        /// <summary>
        /// 获得ID属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">键值</param>
        /// <returns>属性</returns>
        public static string GetId(IDbHelper dbHelper, string tableName, string name, object value)
        {
            return GetProperty(dbHelper, tableName, name, value, BaseBusinessLogic.FieldId);
        }

        #endregion public static string GetId(IDbHelper dbHelper, string tableName, string name, object value) 获得ID属性

        #region public static string GetId(IDbHelper dbHelper, string tableName, string name1, string value1, string name2, string value2) 获得ID属性

        /// <summary>
        /// 获得ID属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>String</returns>
        public static string GetId(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            string returnValue = string.Empty;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            names[1] = name2;
            values[0] = value1;
            values[1] = value2;
            returnValue = GetProperty(dbHelper, tableName, names, values, BaseBusinessLogic.FieldId);
            return returnValue;
        }

        #endregion public static string GetId(IDbHelper dbHelper, string tableName, string name1, string value1, string name2, string value2) 获得ID属性

        #region public static string GetId(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获得ID属性

        /// <summary>
        /// 获得ID属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>属性</returns>
        public static string GetId(IDbHelper dbHelper, string tableName, string[] names, Object[] values)
        {
            return GetProperty(dbHelper, tableName, names, values, BaseBusinessLogic.FieldId);
        }

        #endregion public static string GetId(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获得ID属性

        //
        // 设置属性部分
        //

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string targetField, object targetValue) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string targetField, object targetValue)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            sqlBuilder.SetValue(targetField, targetValue);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string targetField, object targetValue) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string targetField, object targetValue) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">条件字段</param>
        /// <param name="value">条件值</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string targetField, object targetValue)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            sqlBuilder.SetValue(targetField, targetValue);

            // sqlBuilder.SetDBNow(FieldModifiedOn);
            sqlBuilder.SetWhere(name, value);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string targetField, object targetValue) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, object targetValue) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">条件字段</param>
        /// <param name="value1">条件值</param>
        /// <param name="name2">条件字段</param>
        /// <param name="value2">条件值</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, object targetValue)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            sqlBuilder.SetValue(targetField, targetValue);

            // sqlBuilder.SetDBNow(FieldModifiedOn);
            sqlBuilder.SetWhere(name1, value1);
            sqlBuilder.SetWhere(name2, value2);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, object targetValue) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField, object targetValue) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">条件字段</param>
        /// <param name="values">条件值</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField, object targetValue)
        {
            int returnValue = 0;
            if (values == null)
            {
                returnValue = SetProperty(dbHelper, tableName, name, string.Empty, targetField, targetValue);
            }
            else
            {
                for (int i = 0; i < values.Length; i++)
                {
                    returnValue += SetProperty(dbHelper, tableName, name, values[i], targetField, targetValue);
                }
            }
            return returnValue;
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField, object targetValue) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string[] targetFields, Object[] targetValues) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">条件字段</param>
        /// <param name="value">条件值</param>
        /// <param name="targetFields">更新字段</param>
        /// <param name="targetValues">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string[] targetFields, Object[] targetValues)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            for (int i = 0; i < targetFields.Length; i++)
            {
                sqlBuilder.SetValue(targetFields[i], targetValues[i]);
            }

            // sqlBuilder.SetDBNow(BaseBusinessLogic.FieldModifiedOn);
            sqlBuilder.SetWhere(name, value);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string name, object value, string[] targetFields, Object[] targetValues) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] value, string[] targetFields, Object[] targetValues) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">条件字段</param>
        /// <param name="value">条件值</param>
        /// <param name="targetFields">更新字段</param>
        /// <param name="targetValues">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] value, string[] targetFields, Object[] targetValues)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            for (int i = 0; i < targetFields.Length; i++)
            {
                sqlBuilder.SetValue(targetFields[i], targetValues[i]);
            }

            // sqlBuilder.SetDBNow(BaseBusinessLogic.FieldModifiedOn);
            sqlBuilder.SetWhere(name, value);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string name, Object[] value, string[] targetFields, Object[] targetValues) 设置属性

        #region public static int SetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, object targetValue) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">条件字段</param>
        /// <param name="values">条件值</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int SetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, object targetValue)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            sqlBuilder.SetValue(targetField, targetValue);

            // sqlBuilder.SetDBNow(BaseBusinessLogic.FieldModifiedOn);
            sqlBuilder.SetWhere(names, values);
            return sqlBuilder.EndUpdate();
        }

        #endregion public static int SetProperty(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, object targetValue) 设置属性

        #region public static int UpdateRecord(IDbHelper dbHelper, string tableName, string name, string value, string targetField, object targetValue) 更新记录

        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">主键</param>
        /// <param name="value">主键值</param>
        /// <param name="targetField">更新字段</param>
        /// <param name="targetValue">更新值</param>
        /// <returns>影响行数</returns>
        public static int UpdateRecord(IDbHelper dbHelper, string tableName, string name, string value, string targetField, object targetValue)
        {
            int returnValue = 0;
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginUpdate(tableName);
            sqlBuilder.SetValue(targetField, targetValue);
            sqlBuilder.SetWhere(name, value);
            returnValue = sqlBuilder.EndUpdate();
            return returnValue;
        }

        #endregion public static int UpdateRecord(IDbHelper dbHelper, string tableName, string name, string value, string targetField, object targetValue) 更新记录

        #region public static int Insert(IDbHelper dbHelper, string tableName, string[] targetFields, Object[] targetValues) 设置属性

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="targetFields">更新字段</param>
        /// <param name="targetValues">更新值</param>
        /// <returns>影响行数</returns>
        public static int Insert(IDbHelper dbHelper, string tableName, string[] targetFields, Object[] targetValues)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
            sqlBuilder.BeginInsert(tableName);
            for (int i = 0; i < targetFields.Length; i++)
            {
                sqlBuilder.SetValue(targetFields[i], targetValues[i]);
            }
            return sqlBuilder.EndInsert();
        }

        #endregion public static int Insert(IDbHelper dbHelper, string tableName, string[] targetFields, Object[] targetValues) 设置属性

        //
        // 获取ID部分 获得主键数组 string[] 常用
        //

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value) 读取列表部分

        /// <summary>
        /// 读取列表部分
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value)
        {
            string order = string.Empty;
            int topLimit = 0;
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return GetIds(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value) 读取列表部分

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="values">字段值</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values)
        {
            return GetIds(dbHelper, tableName, name, values, BaseBusinessLogic.FieldId);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="targetField">目标字段</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField)
        {
            string sqlQuery = " SELECT " + targetField
                            + "   FROM " + tableName
                            + "  WHERE " + name + " IN (" + BaseBusinessLogic.ObjectsToList(values) + ")";
            DataTable dataTable = dbHelper.Fill(sqlQuery);
            return BaseBusinessLogic.FieldToArray(dataTable, targetField);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, Object[] values, string targetField) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName)
        {
            string order = string.Empty;
            int topLimit = 0;
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetIds(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField)
        {
            int topLimit = 0;
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="order">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField, int topLimit)
        {
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string targetField, int topLimit) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">目标字段名</param>
        /// <param name="value">目标字段值</param>
        /// <param name="targetField">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField, int topLimit)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField, int topLimit) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            int topLimit = 0;
            string order = string.Empty;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetIds(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="targetField">排序</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField)
        {
            int topLimit = 0;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="targetField">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, int topLimit)
        {
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string targetField, int topLimit) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <param name="targetField">目标字段</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField)
        {
            int topLimit = 0;
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string name, object value, string targetField) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">填充目标表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values)
        {
            string fillTableName = tableName;
            string order = string.Empty;
            int topLimit = 0;
            return GetIds(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">填充目标表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="order">排序</param>
        /// <returns>数据集</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField)
        {
            int topLimit = 0;
            return GetIds(dbHelper, tableName, names, values, targetField, topLimit);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField) 获取数据表

        #region public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, int topLimit) 获取数据集

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="targetField">目标字段</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, int topLimit)
        {
            if (string.IsNullOrEmpty(targetField))
            {
                targetField = BaseBusinessLogic.FieldId;
            }

            // 这里是需要完善的功能，完善了这个，是一次重大突破
            string sqlQuery = " SELECT " + targetField + " FROM " + tableName;
            string whereSql = string.Empty;
            if (topLimit != 0)
            {
                switch (dbHelper.CurrentDataBaseType)
                {
                    case DataBaseType.Access:
                    case DataBaseType.SqlServer:
                        sqlQuery = " SELECT TOP " + topLimit.ToString() + targetField + " FROM " + tableName;
                        break;

                    case DataBaseType.Oracle:
                        whereSql = " ROWNUM < = " + topLimit;
                        break;
                }
            }
            string subSql = GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            if (subSql.Length > 0)
            {
                if (whereSql.Length > 0)
                {
                    whereSql = whereSql + BaseBusinessLogic.SQLLogicConditional + subSql;
                }
                else
                {
                    whereSql = subSql;
                }
            }
            if (whereSql.Length > 0)
            {
                sqlQuery += " WHERE " + whereSql;
            }
            if (topLimit != 0)
            {
                switch (dbHelper.CurrentDataBaseType)
                {
                    case DataBaseType.MySql:
                        sqlQuery += " LIMIT 0, " + topLimit;
                        break;
                }
            }
            DataTable dataTable = new DataTable(tableName);
            dbHelper.Fill(dataTable, sqlQuery, dbHelper.MakeParameters(names, values));
            return BaseBusinessLogic.FieldToArray(dataTable, targetField);
        }

        #endregion public static string[] GetIds(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string targetField, int topLimit) 获取数据集

        //
        // 读取列表部分 填充DataTable 常用
        //

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value) 读取列表部分

        /// <summary>
        /// 读取列表部分
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value)
        {
            string order = string.Empty;
            int topLimit = 0;
            string[] names = new string[1];
            object[] values = new object[1];
            names[0] = name;
            values[0] = value;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value) 读取列表部分

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, Object[] values) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="values">字段值</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, Object[] values)
        {
            return GetDT(dbHelper, tableName, name, values, string.Empty);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, Object[] values) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName)
        {
            string order = string.Empty;
            int topLimit = 0;
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order)
        {
            int topLimit = 0;
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="ids">主键数组</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids)
        {
            return GetDT(dbHelper, tableName, BaseBusinessLogic.FieldId, ids);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="ids">主键数组</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids, string order)
        {
            return GetDT(dbHelper, tableName, BaseBusinessLogic.FieldId, ids, order);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, Object[] ids, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="order">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order, int topLimit)
        {
            string[] names = new string[0];
            Object[] values = new Object[0];
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string order, int topLimit) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">目标字段名</param>
        /// <param name="value">目标字段值</param>
        /// <param name="order">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order, int topLimit)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order, int topLimit) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            int topLimit = 0;
            string order = string.Empty;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order)
        {
            int topLimit = 0;
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order, int topLimit) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="order">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order, int topLimit)
        {
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string order, int topLimit) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order)
        {
            DataTable dataTable = new DataTable(tableName);
            string sqlQuery = " SELECT * "
                            + "   FROM " + tableName;
            if (value == null)
            {
                sqlQuery += "  WHERE " + name + " IS NULL";
            }
            else
            {
                sqlQuery += "  WHERE " + name + " = " + dbHelper.GetParameter(name);
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            if (value == null)
            {
                dataTable = dbHelper.Fill(sqlQuery);
            }
            else
            {
                dataTable = dbHelper.Fill(sqlQuery, dbHelper.MakeParameters(name, value));
            }
            return dataTable;
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object value, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object[] values, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object[] values, string order)
        {
            string sqlQuery = " SELECT * "
                            + "   FROM " + tableName;
            if (values == null)
            {
                sqlQuery += "  WHERE " + name + " IS NULL";
            }
            else
            {
                sqlQuery += "  WHERE " + name + " IN (" + BaseBusinessLogic.ObjectsToList(values) + ")";
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            return dbHelper.Fill(sqlQuery);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string name, object[] values, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">填充目标表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values)
        {
            string fillTableName = tableName;
            string order = string.Empty;
            int topLimit = 0;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order) 获取数据表

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">填充目标表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="order">排序</param>
        /// <returns>数据集</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order)
        {
            int topLimit = 0;
            return GetDT(dbHelper, tableName, names, values, order, topLimit);
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order) 获取数据表

        #region public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order, int topLimit) 获取数据集

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="names">字段名</param>
        /// <param name="values">字段值</param>
        /// <param name="order">排序</param>
        /// <param name="topLimit">前几个记录</param>
        /// <returns>数据表</returns>
        public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order, int topLimit)
        {
            // 这里是需要完善的功能，完善了这个，是一次重大突破
            string sqlQuery = " SELECT * FROM " + tableName;
            string whereSql = string.Empty;
            if (topLimit != 0)
            {
                switch (dbHelper.CurrentDataBaseType)
                {
                    case DataBaseType.Access:
                    case DataBaseType.SqlServer:
                        sqlQuery = " SELECT TOP " + topLimit.ToString() + " * FROM " + tableName;
                        break;

                    case DataBaseType.Oracle:
                        whereSql = " ROWNUM < = " + topLimit;
                        break;
                }
            }
            string subSql = GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            if (subSql.Length > 0)
            {
                if (whereSql.Length > 0)
                {
                    whereSql = whereSql + BaseBusinessLogic.SQLLogicConditional + subSql;
                }
                else
                {
                    whereSql = subSql;
                }
            }
            if (whereSql.Length > 0)
            {
                sqlQuery += " WHERE " + whereSql;
            }
            if ((order != null) && (order.Length > 0))
            {
                sqlQuery += " ORDER BY " + order;
            }
            if (topLimit != 0)
            {
                switch (dbHelper.CurrentDataBaseType)
                {
                    case DataBaseType.MySql:
                        sqlQuery += " LIMIT 0, " + topLimit;
                        break;
                }
            }
            DataTable dataTable = new DataTable(tableName);
            if ((names != null) && (values != null) && (names.Length > 0) && (values.Length > 0))
            {
                dataTable = dbHelper.Fill(sqlQuery, dbHelper.MakeParameters(names, values));
            }
            else
            {
                dataTable = dbHelper.Fill(sqlQuery);
            }
            return dataTable;
        }

        #endregion public static DataTable GetDT(IDbHelper dbHelper, string tableName, string[] names, Object[] values, string order, int topLimit) 获取数据集

        //
        // 读取列表部分 不常用
        //

        #region public static DataTable GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName) 通过存储过程获取表数据

        /// <summary>
        /// 通过存储过程获取表数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="procedureName">存储过程名</param>
        /// <param name="tableName">填充表</param>
        /// <returns>数据集</returns>
        public static DataTable GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName)
        {
            return dbHelper.ExecuteProcedureForDataTable(procedureName, tableName, null);
        }

        #endregion public static DataTable GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName) 通过存储过程获取表数据

        #region public static DataSet GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName, string id) 通过存储过程获取表数据

        /// <summary>
        /// 通过存储过程获取表数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="procedureName">存储过程名</param>
        /// <param name="tableName">填充表</param>
        /// <param name="id">主键值</param>
        /// <returns>数据集</returns>
        public static DataTable GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName, string id)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = BaseBusinessLogic.FieldId;
            values[0] = id;
            return dbHelper.ExecuteProcedureForDataTable(procedureName, tableName, dbHelper.MakeParameters(names, values));
        }

        #endregion public static DataSet GetFromProcedure(IDbHelper dbHelper, string procedureName, string tableName, string id) 通过存储过程获取表数据

        //
        // 记录是否存在
        //

        #region public static bool Exists(IDbHelper dbHelper, string tableName, object id) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="id">字段值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, object id)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = BaseBusinessLogic.FieldId;
            values[0] = id;
            return Exists(dbHelper, tableName, names, values);
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, object id) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">目标字段名</param>
        /// <param name="value">目标字段值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return Exists(dbHelper, tableName, names, values);
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, object[] ids) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="ids">字段值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, object[] ids)
        {
            bool returnValue = false;
            for (int i = 0; i < ids.Length; i++)
            {
                returnValue = Exists(dbHelper, tableName, BaseBusinessLogic.FieldId, ids[i]);
                if (returnValue)
                {
                    break;
                }
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, object[] ids) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name, object[] values) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">字段名</param>
        /// <param name="values">字段值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name, object[] values)
        {
            bool returnValue = false;
            for (int i = 0; i < values.Length; i++)
            {
                returnValue = Exists(dbHelper, tableName, name, values[i]);
                if (returnValue)
                {
                    break;
                }
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name, object[] values) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value, object id) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">目标字段名</param>
        /// <param name="value">目标字段值</param>
        /// <param name="id">主键值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value, object id)
        {
            bool returnValue = false;
            string sqlQuery = " SELECT COUNT(*) FROM " + tableName;
            if (name == null)
            {
                sqlQuery += " WHERE (" + name + " IS NULL ) ";
            }
            else
            {
                sqlQuery += " WHERE (" + name + " = " + dbHelper.GetParameter(name) + ") ";
            }
            if (id != null)
            {
                sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + BaseBusinessLogic.FieldId + " <> " + dbHelper.GetParameter(BaseBusinessLogic.FieldId) + " ) ";
            }
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name;
            values[0] = value;
            if (id != null)
            {
                names[1] = BaseBusinessLogic.FieldId;
                values[1] = id;
            }
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = int.Parse(returnObject.ToString()) > 0;
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name, object value, object id) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            names[1] = name2;
            values[0] = value1;
            values[1] = value2;
            return Exists(dbHelper, tableName, names, values);
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string name, object id) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="name">目标字段名</param>
        /// <param name="id">主键值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, object id)
        {
            return Exists(dbHelper, tableName, name1, value1, name2, value2, BaseBusinessLogic.FieldId, id);
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string name, object id) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string primaryKey, object id) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <param name="name">目标字段名</param>
        /// <param name="id">主键值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string primaryKey, object id)
        {
            bool returnValue = false;
            string sqlQuery = " SELECT COUNT(*) FROM " + tableName;
            if (value1 == null)
            {
                sqlQuery += " WHERE (" + name1 + " IS NULL) ";
            }
            else
            {
                sqlQuery += " WHERE (" + name1 + " = " + dbHelper.GetParameter(name1) + ") ";
            }
            if (value2 == null)
            {
                sqlQuery += BaseBusinessLogic.SQLLogicConditional + "(" + name2 + " IS NULL) ";
            }
            else
            {
                sqlQuery += BaseBusinessLogic.SQLLogicConditional + "(" + name2 + " = " + dbHelper.GetParameter(name2) + ") ";
            }
            if (id != null)
            {
                sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + primaryKey + " <> " + dbHelper.GetParameter(primaryKey) + ") ";
            }
            string[] names = new string[3];
            Object[] values = new Object[3];
            names[0] = name1;
            values[0] = value1;
            names[1] = name2;
            values[1] = value2;
            if (id != null)
            {
                names[2] = primaryKey;
                values[2] = id;
            }
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = int.Parse(returnObject.ToString()) > 0;
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2, string primaryKey, object id) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values)
        {
            bool returnValue = false;
            string sqlQuery = " SELECT COUNT(*) "
                + " FROM " + tableName
                + " WHERE " + GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = int.Parse(returnObject.ToString()) > 0;
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values) 记录是否存在

        #region public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values, string primaryKey, object id) 记录是否存在

        /// <summary>
        /// 记录是否存在
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <param name="targetField">获取字段</param>
        /// <param name="primaryKey">目标字段名</param>
        /// <param name="id">目标字段值</param>
        /// <returns>bool</returns>
        public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values, string primaryKey, object id)
        {
            bool returnValue = false;
            string sqlQuery = " SELECT COUNT(*) "
                + " FROM " + tableName
                + " WHERE " + GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + primaryKey + " <> '" + id + "' ) ";
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                returnValue = int.Parse(returnObject.ToString()) > 0;
            }
            return returnValue;
        }

        #endregion public static bool Exists(IDbHelper dbHelper, string tableName, string[] names, object[] values, string primaryKey, object id) 记录是否存在

        //
        // 删除数据库方法
        //

        #region public static int Delete(IDbHelper dbHelper, string tableName) 删除表中的所有数据

        /// <summary>
        /// 删除表中的所有数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表</param>
        /// <returns>影响行数</returns>
        public static int Delete(IDbHelper dbHelper, string tableName)
        {
            return BatchDelete(dbHelper, tableName, new string[0], new Object[0]);
        }

        #endregion public static int Delete(IDbHelper dbHelper, string tableName) 删除表中的所有数据

        #region public static int Delete(IDbHelper dbHelper, string tableName, object id) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表</param>
        /// <param name="id">字段值</param>
        /// <returns>影响行数</returns>
        public static int Delete(IDbHelper dbHelper, string tableName, object id)
        {
            return Delete(dbHelper, tableName, BaseBusinessLogic.FieldId, id);
        }

        #endregion public static int Delete(IDbHelper dbHelper, string tableName, object id) 删除表格数据

        #region public static int BatchDelete(IDbHelper dbHelper, string tableName, object[] ids) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表</param>
        /// <param name="ids">字段值</param>
        /// <returns>影响行数</returns>
        public static int BatchDelete(IDbHelper dbHelper, string tableName, object[] ids)
        {
            int returnValue = 0;
            for (int i = 0; i < ids.Length; i++)
            {
                returnValue += Delete(dbHelper, tableName, BaseBusinessLogic.FieldId, ids[i]);
            }
            return returnValue;
        }

        #endregion public static int BatchDelete(IDbHelper dbHelper, string tableName, object[] ids) 删除表格数据

        #region public static int BatchDelete(IDbHelper dbHelper, string tableName, string name, Object[] values) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表</param>
        /// <param name="name">目标字段名</param>
        /// <param name="values">目标字段值</param>
        /// <returns>影响行数</returns>
        public static int BatchDelete(IDbHelper dbHelper, string tableName, string name, Object[] values)
        {
            int returnValue = 0;
            for (int i = 0; i < values.Length; i++)
            {
                returnValue += Delete(dbHelper, tableName, name, values[i]);
            }
            return returnValue;
        }

        #endregion public static int BatchDelete(IDbHelper dbHelper, string tableName, string name, Object[] values) 删除表格数据

        #region public static int Delete(IDbHelper dbHelper, string tableName, string name, object value) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表格名</param>
        /// <param name="name">主键</param>
        /// <param name="value">主键值</param>
        /// <returns>影响行数</returns>
        public static int Delete(IDbHelper dbHelper, string tableName, string name, object value)
        {
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = name;
            values[0] = value;
            return BatchDelete(dbHelper, tableName, names, values);
        }

        #endregion public static int Delete(IDbHelper dbHelper, string tableName, string name, object value) 删除表格数据

        #region public static int Delete(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>影响行数</returns>
        public static int Delete(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            names[1] = name2;
            values[0] = value1;
            values[1] = value2;
            return BatchDelete(dbHelper, tableName, names, values);
        }

        #endregion public static int Delete(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 删除表格数据

        #region public int static BatchDelete(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 删除表格数据

        /// <summary>
        /// 删除表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <returns>影响行数</returns>
        public static int BatchDelete(IDbHelper dbHelper, string tableName, string[] names, Object[] values)
        {
            string sqlQuery = " DELETE " + " FROM " + tableName;
            string whereString = GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            if (whereString.Length > 0)
            {
                sqlQuery += " WHERE " + whereString;
            }
            return dbHelper.ExecuteNonQuery(sqlQuery, dbHelper.MakeParameters(names, values));
        }

        #endregion public int static BatchDelete(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 删除表格数据

        #region public static int Truncate(IDbHelper dbHelper, string tableName) 截断表格数据

        /// <summary>
        /// 截断表格数据
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表格</param>
        /// <returns>是否成功</returns>
        public static int Truncate(IDbHelper dbHelper, string tableName)
        {
            string sqlQuery = " Truncate Table " + tableName;
            return dbHelper.ExecuteNonQuery(sqlQuery);
        }

        #endregion public static int Truncate(IDbHelper dbHelper, string tableName) 截断表格数据

        //
        // 锁定表记录
        //

        #region public static int LockNoWait(IDbHelper dbHelper, string tableName, string id) 锁定表记录

        /// <summary>
        /// 锁定表记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="id">字段值</param>
        /// <returns>锁定的行数</returns>
        public static int LockNoWait(IDbHelper dbHelper, string tableName, string id)
        {
            return LockNoWait(dbHelper, tableName, BaseBusinessLogic.FieldId, id);
        }

        #endregion public static int LockNoWait(IDbHelper dbHelper, string tableName, string id) 锁定表记录

        #region public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] ids) 锁定表记录

        /// <summary>
        /// 锁定表记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="ids">字段值</param>
        /// <returns>锁定的行数</returns>
        public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] ids)
        {
            int returnValue = 0;
            for (int i = 0; i < ids.Length; i++)
            {
                returnValue += LockNoWait(dbHelper, tableName, BaseBusinessLogic.FieldId, ids[i]);
            }
            return returnValue;
        }

        #endregion public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] ids) 锁定表记录

        #region public static int LockNoWait(IDbHelper dbHelper, string tableName, string name, object value) 锁定表记录

        /// <summary>
        /// 锁定表记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name">目标字段名</param>
        /// <param name="value">目标字段值</param>
        /// <param name="id">主键值</param>
        /// <returns>锁定的行数</returns>
        public static int LockNoWait(IDbHelper dbHelper, string tableName, string name, object value)
        {
            int returnValue = 0;
            string sqlQuery = " SELECT " + BaseBusinessLogic.FieldId + " FROM " + tableName;
            if (name == null)
            {
                sqlQuery += " WHERE (" + name + " IS NULL ) ";
            }
            else
            {
                sqlQuery += " WHERE (" + name + " = " + dbHelper.GetParameter(name) + ")";
            }
            sqlQuery += " FOR UPDATE NOWAIT ";
            try
            {
                DataSet dataSet = new DataSet();
                dbHelper.Fill(dataSet, sqlQuery, "ForUpdateNoWait", dbHelper.MakeParameters(name, value));
                returnValue = dataSet.Tables["ForUpdateNoWait"].Rows.Count;
            }
            catch
            {
                returnValue = -1;
            }
            return returnValue;
        }

        #endregion public static int LockNoWait(IDbHelper dbHelper, string tableName, string name, object value) 锁定表记录

        #region public static int LockNoWait(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 记录是否存在

        /// <summary>
        /// 锁定表记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="name1">目标字段名1</param>
        /// <param name="value1">目标字段值1</param>
        /// <param name="name2">目标字段名2</param>
        /// <param name="value2">目标字段值2</param>
        /// <returns>锁定的行数</returns>
        public static int LockNoWait(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2)
        {
            string[] names = new string[2];
            Object[] values = new Object[2];
            names[0] = name1;
            names[1] = name2;
            values[0] = value1;
            values[1] = value2;
            return LockNoWait(dbHelper, tableName, names, values);
        }

        #endregion public static int LockNoWait(IDbHelper dbHelper, string tableName, string name1, object value1, string name2, object value2) 记录是否存在

        #region public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 记录是否存在

        /// <summary>
        /// 锁定表记录
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表名</param>
        /// <param name="names">字段名数组</param>
        /// <param name="values">键值数组</param>
        /// <param name="targetField">获取字段</param>
        /// <returns>锁定的行数</returns>
        public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] names, Object[] values)
        {
            int returnValue = 0;
            string sqlQuery = " SELECT " + BaseBusinessLogic.FieldId
                + " FROM " + tableName
                + " WHERE " + GetWhereString(dbHelper, names, ref values, BaseBusinessLogic.SQLLogicConditional);
            sqlQuery += " FOR UPDATE NOWAIT ";
            try
            {
                DataSet dataSet = new DataSet();
                dbHelper.Fill(dataSet, sqlQuery, "ForUpdateNoWait", dbHelper.MakeParameters(names, values));
                returnValue = dataSet.Tables["ForUpdateNoWait"].Rows.Count;
            }
            catch
            {
                returnValue = -1;
            }
            return returnValue;
        }

        #endregion public static int LockNoWait(IDbHelper dbHelper, string tableName, string[] names, Object[] values) 记录是否存在

        //
        // 树型结构的算法
        //

        #region public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        /// <summary>
        /// 获取父节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">只需要主键</param>
        /// <returns>数据表</returns>
        public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly)
        {
            string sqlQuery = string.Empty;
            if (idOnly)
            {
                sqlQuery = "   SELECT " + BaseBusinessLogic.FieldId;
            }
            else
            {
                sqlQuery = "   SELECT * ";
            }
            sqlQuery += "     FROM " + tableName;
            switch (dbHelper.CurrentDataBaseType)
            {
                case DataBaseType.Access:
                case DataBaseType.SqlServer:
                    sqlQuery += "    WHERE (LEFT(" + dbHelper.GetParameter(fieldCode) + ", LEN(" + fieldCode + ")) = " + fieldCode + ") ";
                    break;

                case DataBaseType.Oracle:
                    sqlQuery += "    WHERE (SUBSTR(" + dbHelper.GetParameter(fieldCode) + ", 1, LENGTH(" + fieldCode + ")) = " + fieldCode + ") ";
                    break;
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = fieldCode;
            values[0] = code;
            DataTable dataTable = new DataTable(tableName);
            dbHelper.Fill(dataTable, sqlQuery, dbHelper.MakeParameters(names, values));
            return dataTable;
        }

        #endregion public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        #region public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order, bool idOnly) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldId">主键字段</param>
        /// <param name="id">值</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">只需要主键</param>
        /// <returns>数据表</returns>
        public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order, bool idOnly)
        {
            string sqlQuery = string.Empty;
            if (idOnly)
            {
                sqlQuery = "   SELECT " + fieldId;
            }
            else
            {
                sqlQuery = "   SELECT * ";
            }
            sqlQuery += "          FROM " + tableName
                     + "    START WITH " + fieldId + " = " + dbHelper.GetParameter(fieldId)
                     + "  CONNECT BY PRIOR " + fieldId + " = " + fieldParentId;
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            string[] names = new string[1];
            names[0] = fieldId;
            Object[] values = new Object[1];
            values[0] = id;
            DataTable dataTable = new DataTable(tableName);
            dbHelper.Fill(dataTable, sqlQuery, dbHelper.MakeParameters(names, values));
            return dataTable;
        }

        #endregion public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order, bool idOnly) 获取子节点列表

        #region public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string[] ids, string fieldParentId, string order, bool idOnly) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldId">主键字段</param>
        /// <param name="ids">主键数组</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">只需要主键</param>
        /// <returns>数据表</returns>
        public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string[] ids, string fieldParentId, string order, bool idOnly)
        {
            string sqlQuery = string.Empty;
            if (idOnly)
            {
                sqlQuery = "   SELECT " + fieldId;
            }
            else
            {
                sqlQuery = "   SELECT * ";
            }
            sqlQuery += "          FROM " + tableName
                     + "    START WITH " + fieldId + " IN (" + BaseBusinessLogic.ObjectsToList(ids) + ")"
                     + "  CONNECT BY PRIOR " + fieldId + " = " + fieldParentId;
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            return dbHelper.Fill(sqlQuery);
        }

        #endregion public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string[] ids, string fieldParentId, string order, bool idOnly) 获取子节点列表

        #region private static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">只需要主键</param>
        /// <returns>数据表</returns>
        private static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly)
        {
            string sqlQuery = string.Empty;
            if (idOnly)
            {
                sqlQuery = "   SELECT " + BaseBusinessLogic.FieldId;
            }
            else
            {
                sqlQuery = "   SELECT * ";
            }
            sqlQuery += "     FROM " + tableName;
            switch (dbHelper.CurrentDataBaseType)
            {
                case DataBaseType.Access:
                case DataBaseType.SqlServer:
                    sqlQuery += "    WHERE (LEFT(" + fieldCode + ", LEN(" + dbHelper.GetParameter(fieldCode) + ")) = " + dbHelper.GetParameter(fieldCode) + " ) ";
                    break;

                case DataBaseType.Oracle:
                    sqlQuery += "    WHERE (SUBSTR(" + fieldCode + ", 1, LENGTH(" + dbHelper.GetParameter(fieldCode) + ")) = " + dbHelper.GetParameter(fieldCode) + " ) ";
                    break;
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            string[] names = new string[2];
            names[0] = fieldCode;
            names[1] = fieldCode;
            Object[] values = new Object[2];
            values[0] = code;
            values[1] = code;
            DataTable dataTable = new DataTable(tableName);
            dbHelper.Fill(dataTable, sqlQuery, dbHelper.MakeParameters(names, values));
            return dataTable;
        }

        #endregion private static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly) 获取子节点列表

        #region private static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly) 获取父子节点列表

        /// <summary>
        /// 获取父子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <param name="idOnly">只需要主键</param>
        /// <returns>数据表</returns>
        private static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly)
        {
            string sqlQuery = string.Empty;
            if (idOnly)
            {
                sqlQuery = "   SELECT " + BaseBusinessLogic.FieldId;
            }
            else
            {
                sqlQuery = "   SELECT * ";
            }
            sqlQuery += "     FROM " + tableName;
            switch (dbHelper.CurrentDataBaseType)
            {
                case DataBaseType.Access:
                case DataBaseType.SqlServer:
                    sqlQuery += "    WHERE (LEFT(" + fieldCode + ", LEN(" + dbHelper.GetParameter(fieldCode) + ")) = " + dbHelper.GetParameter(fieldCode) + ") ";
                    sqlQuery += "          OR (LEFT(" + dbHelper.GetParameter(fieldCode) + ", LEN(" + fieldCode + ")) = " + fieldCode + ") ";
                    break;

                case DataBaseType.Oracle:
                    sqlQuery += "    WHERE (SUBSTR(" + fieldCode + ", 1, LENGTH(" + dbHelper.GetParameter(fieldCode) + ")) = " + dbHelper.GetParameter(fieldCode) + ") ";
                    sqlQuery += "          OR (" + fieldCode + " = SUBSTR(" + dbHelper.GetParameter(fieldCode) + ", 1, LENGTH(" + fieldCode + "))) ";
                    break;
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            string[] names = new string[3];
            names[0] = fieldCode;
            names[1] = fieldCode;
            names[2] = fieldCode;
            Object[] values = new Object[3];
            values[0] = code;
            values[1] = code;
            values[2] = code;
            DataTable dataTable = new DataTable();
            dbHelper.Fill(dataTable, sqlQuery, dbHelper.MakeParameters(names, values));
            return dataTable;
        }

        #endregion private static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order, bool idOnly) 获取父子节点列表

        #region public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        /// <summary>
        /// 获取父节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return GetParentsByCode(dbHelper, tableName, fieldCode, code, order, false);
        }

        #endregion public static DataTable GetParentsByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        #region public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldId">主键字段</param>
        /// <param name="id">值</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order)
        {
            return GetChildrens(dbHelper, tableName, fieldId, id, fieldParentId, order, false);
        }

        #endregion public static DataTable GetChildrens(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        #region public static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return GetChildrensByCode(dbHelper, tableName, fieldCode, code, order, false);
        }

        #endregion public static DataTable GetChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取子节点列表

        #region public static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父子节点列表

        /// <summary>
        /// 获取父子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return GetParentChildrensByCode(dbHelper, tableName, fieldCode, code, order, false);
        }

        #endregion public static DataTable GetParentChildrensByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父子节点列表

        #region public static string[] GetParentsIDByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        /// <summary>
        /// 获取父节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>主键数组</returns>
        public static string[] GetParentsIDByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return BaseBusinessLogic.FieldToArray(GetParentsByCode(dbHelper, tableName, fieldCode, code, order, true), BaseBusinessLogic.FieldId);
        }

        #endregion public static string[] GetParentsIDByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父节点列表

        #region public static string[] GetChildrensId(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldId">主键字段</param>
        /// <param name="id">值</param>
        /// <param name="fieldParentId">父亲节点字段</param>
        /// <param name="order">排序</param>
        /// <returns>主键数组</returns>
        public static string[] GetChildrensId(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order)
        {
            return BaseBusinessLogic.FieldToArray(GetChildrens(dbHelper, tableName, fieldId, id, fieldParentId, order, true), BaseBusinessLogic.FieldId);
        }

        #endregion public static string[] GetChildrensId(IDbHelper dbHelper, string tableName, string fieldId, string id, string fieldParentId, string order) 获取子节点列表

        #region public static string[] GetChildrensByIDCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取子节点列表

        /// <summary>
        /// 获取子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>主键数组</returns>
        public static string[] GetChildrensIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return BaseBusinessLogic.FieldToArray(GetChildrensByCode(dbHelper, tableName, fieldCode, code, order, true), BaseBusinessLogic.FieldId);
        }

        #endregion public static string[] GetChildrensByIDCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取子节点列表

        #region public static string[] GetParentChildrensIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父子节点列表

        /// <summary>
        /// 获取父子节点列表
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">目标表明</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编码</param>
        /// <param name="order">排序</param>
        /// <returns>主键数组</returns>
        public static string[] GetParentChildrensIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order)
        {
            return BaseBusinessLogic.FieldToArray(GetParentChildrensByCode(dbHelper, tableName, fieldCode, code, order, true), BaseBusinessLogic.FieldId);
        }

        #endregion public static string[] GetParentChildrensIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code, string order) 获取父子节点列表

        #region public static string GetParentIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code) 获取父节点

        /// <summary>
        /// 获取父节点
        /// </summary>
        /// <param name="tableName">目标表名</param>
        /// <param name="fieldCode">编码字段</param>
        /// <param name="code">编号</param>
        /// <returns>主键</returns>
        public static string GetParentIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code)
        {
            string parentId = string.Empty;
            string sqlQuery = " SELECT MAX(Id) AS Id "
                            + "    FROM " + tableName
                            + "  WHERE (LEFT(" + dbHelper.GetParameter(fieldCode) + ", LEN(" + fieldCode + ")) = " + fieldCode + ") "
                            + "    AND " + fieldCode + " <>  '" + code + " ' ";
            string[] names = new string[1];
            Object[] values = new Object[1];
            names[0] = fieldCode;
            values[0] = code;
            object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
            if (returnObject != null)
            {
                parentId = returnObject.ToString();
            }
            return parentId;
        }

        #endregion public static string GetParentIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code) 获取父节点
    }
}